PROGRAM MAPS
USE POLYMORPHIC_COMPLEXTAYLOR
TYPE(DAMAP) ROT,SEXT,TOTAL_DA_MAP,TOTAL_TPSA_MAP
REAL(DP) ANGLE,KICK_STRENGTH
type(taylor) T,T_DA,T_TPSA
TYPE(REAL_8) Y,X1,X2
integer mf
REAL(DP) :: PRINT_PRECISION = 1.D-10
mf=20
open(unit=mf,file='results.txt')
CALL INIT(NO1=2,ND1=1,NP1=0,NDPT1 =0)     !   <------------------ init for maps in ND1 degrees of freedom

CALL ALLOC(ROT,SEXT,TOTAL_DA_MAP,TOTAL_TPSA_MAP)
CALL ALLOC(Y,X1,X2)
call alloc(t)

ANGLE=30.0_DP * PI/180.0_DP
Y=ANGLE 

ROT%V(1)= (COS(ANGLE).MONO.'10') + (SIN(ANGLE).MONO.'01') -1.d-1
ROT%V(2)= (COS(ANGLE).MONO.'01') - (SIN(ANGLE).MONO.'10') -2.d-1
KICK_STRENGTH=3.0_DP
SEXT%V(1)= (1.0_DP.MONO.'10') +.01d0
SEXT%V(2)= (1.0_DP.MONO.'01') + (KICK_STRENGTH.MONO.'20') +.02d0
write(20,*) " Map of Rotation "
CALL PRINT(ROT,mf)
write(20,*) " Map of Sextupole kick "
CALL PRINT(SEXT,mf)
TOTAL_DA_MAP=SEXT*ROT   ! <---- * PERFORMS A DA-CONCATENATION OF TWO DAMAPS
write(20,*) " Map for SEXT*ROT  "
CALL PRINT(TOTAL_DA_MAP,mf)
TOTAL_TPSA_MAP=SEXT.o.ROT   ! <---- * PERFORMS A TPSA-CONCATENATION OF TWO DAMAPS
write(20,*) " Map for SEXT.o.ROT " 
CALL PRINT(TOTAL_TPSA_MAP,mf)


! Construct a Taylor Series t
call alloc(T,T_DA,T_TPSA)

T=1.D0+(2.D0.MONO.'1')+(1.D0.MONO.'11')

T_TPSA=T.O.TOTAL_TPSA_MAP

T_DA=T*TOTAL_DA_MAP

WRITE(20,*) " "
WRITE(20,*) " TAYLOR SERIES T "
CALL PRINT(T,MF)
WRITE(20,*) " "
WRITE(20,*) " TAYLOR SERIES T.O.TOTAL_TPSA_MAP "
CALL PRINT(T_TPSA,MF)
WRITE(20,*) " "
WRITE(20,*) " TAYLOR SERIES T*TOTAL_DA_MAP "
CALL PRINT(T_DA,MF)

! A FEW THINGS WHICH SHOULD BE ZERO


T_TPSA=T_TPSA-2.D0*(TOTAL_TPSA_MAP%V(1))-TOTAL_TPSA_MAP%V(1)*TOTAL_TPSA_MAP%V(2)-1.D0

WRITE(20,*) " "
WRITE(20,*) " COMPARING T.O.TOTAL_TPSA_MAP WITH DEFINITION "
WRITE(20,*) " WHERE T=1.D0+(2.D0.MONO.'1')+(1.D0.MONO.'11') "

CALL PRINT(T_TPSA,MF,PRINT_PRECISION)

WRITE(20,*) " "
WRITE(20,*) " COMPARING T.O.TOTAL_DA_MAP WITH DEFINITION "
WRITE(20,*) " WHERE  T=1.D0+(2.D0.MONO.'1')+(1.D0.MONO.'11') "

T_DA=T_DA-2.D0*(TOTAL_DA_MAP%V(1)-(TOTAL_DA_MAP%V(1).SUB.'0')) &
-(TOTAL_DA_MAP%V(1)-(TOTAL_DA_MAP%V(1).SUB.'0'))*(TOTAL_DA_MAP%V(2)-(TOTAL_DA_MAP%V(2).SUB.'0'))-1.D0

CALL PRINT(T_DA,MF,PRINT_PRECISION)




call kill(T,T_DA,T_TPSA)
CALL KILL(ROT,SEXT,TOTAL_DA_MAP,TOTAL_TPSA_MAP)
CALL KILL(Y,X1,X2)

close(20)
END PROGRAM MAPS

